# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libassuan
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.5.6
pkgrel=1
pkgdesc="A IPC library used by some GnuPG related software (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('spdx: LGPL-2.1-or-later OR GPL-3.0-or-later')
url="https://gnupg.org/related_software/libassuan"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libgpg-error")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://gnupg.org/ftp/gcrypt/${_realname}/${_realname}-${pkgver}.tar.bz2"{,.sig}
        0001-fix-def-files.mingw.patch
        0002-enable-silent-rules.mingw.patch
        0004-enable-gnu.mingw.patch
        0005-better-check-for-stpcpy.mingw.patch
        0006-fix-broken-version.patch)
#These might be signed by any of these keys https://gnupg.org/signature_key.html
validpgpkeys=('6DAA6E64A76D2840571B4902528897B826403ADA'
              'D8692123C4065DEA5E0F3AB5249B39D24F25E3B6'
              '46CC730865BB5C78EBABADCF04376F3EE0856959'
              '031EC2536E580D8EA286A9F22071B08A33BD3F06'
              'D238EA65D64C67ED4C3073F28A861B1C7EFD60D9')
sha256sums=('e9fd27218d5394904e4e39788f9b1742711c3e6b41689a31aa3380bd5aa4f426'
            'SKIP'
            '7aca3f3fd476ca9488c41a3c74c36f22f84957320066aa26dd47535ec2d65bce'
            'c61974720f41e982cadcfedbb3f9f77aa856bc5a59dcc3d76bbc30ff0d3b2c8a'
            '7dfedfe37e3d9719f5560d311a9036903cc728b65b868a110af27e29cf4ffdee'
            '4ae136681100906ddd67ef72de697410c12e604d0704bad4c3cebcc181120882'
            '21867abdb907285250289399721c8ddfbd16f96cce3fc5dc20a14a39a931bd7d')

_apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -p1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}

  _apply_patch_with_msg \
   0001-fix-def-files.mingw.patch \
   0002-enable-silent-rules.mingw.patch \
   0004-enable-gnu.mingw.patch \
   0005-better-check-for-stpcpy.mingw.patch \
   0006-fix-broken-version.patch

  autoreconf -fi
}

build() {
  if [ ${MINGW_CHOST} = "x86_64-w64-mingw32" ]; then
    CFLAGS+=" -DHAVE_DOSISH_SYSTEM=1"
  fi

  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LIB"
}
